import { RouteItem } from '../config/routes';

// 使用字符串标识符，在 RouterContext 中会转换为实际的组件
export const dynamicRoutes: RouteItem[] = [
  {
    key: 'dashboard',
    path: '/dashboard',
    label: '仪表板',
    icon: 'DashboardOutlined' as any, // 使用类型断言
    component: 'Dashboard' as any,    // 使用类型断言
  },
  {
    key: 'user',
    path: '/user',
    label: '用户管理',
    icon: 'UserOutlined' as any,
    component: undefined, // 父级菜单通常没有组件
    children: [
      {
        key: 'user-list',
        path: '/user/list',
        label: '用户列表',
        icon: undefined,
        component: 'UserManagement' as any,
      },
      {
        key: 'user-profile',
        path: '/user/profile/:id',
        label: '用户详情',
        icon: undefined,
        component: 'UserProfile' as any,
        hideInMenu: true
      }
    ]
  },
  {
    key: 'products',
    path: '/products',
    label: '商品管理',
    icon: 'ShoppingOutlined' as any,
    permission: ['product_manager'],
    component: undefined,
    children: [
      {
        key: 'product-list',
        path: '/products/list',
        label: '商品列表',
        icon: undefined,
        component: 'ProductList' as any,
      },
      {
        key: 'product-categories',
        path: '/products/categories',
        label: '商品分类',
        icon: undefined,
        component: 'ProductCategories' as any,
      }
    ]
  },
  {
    key: 'orders',
    path: '/orders',
    label: '订单管理',
    icon: 'OrderedListOutlined' as any,
    permission: ['order_manager'],
    component: undefined,
    children: [
      {
        key: 'order-list',
        path: '/orders/list',
        label: '订单列表',
        icon: undefined,
        component: 'OrderList' as any,
      },
      {
        key: 'order-detail',
        path: '/orders/detail/:id',
        label: '订单详情',
        icon: undefined,
        component: 'OrderDetail' as any,
        hideInMenu: true
      }
    ]
  },
  {
    key: 'system',
    path: '/system',
    label: '系统管理',
    icon: 'SettingOutlined' as any,
    permission: ['admin'],
    component: undefined,
    children: [
      {
        key: 'role',
        path: '/system/role',
        label: '角色管理',
        icon: undefined,
        component: 'RoleManagement' as any,
      },
      {
        key: 'menu',
        path: '/system/menu',
        label: '菜单管理',
        icon: undefined,
        component: 'MenuManagement' as any,
      },
      {
        key: 'settings',
        path: '/system/settings',
        label: '系统设置',
        icon: undefined,
        component: 'SystemSettings' as any,
      }
    ]
  }
];

// 模拟获取动态路由的 API
export const api = {
  getRoutes: async (): Promise<RouteItem[]> => {
    // 模拟网络请求
    await new Promise(resolve => setTimeout(resolve, 1000));
    return dynamicRoutes;
  },
  
  getUserPermissions: async (): Promise<string[]> => {
    // 模拟获取用户权限
    await new Promise(resolve => setTimeout(resolve, 500));
    return ['admin', 'product_manager', 'order_manager'];
  }
};